﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>退库申请单-发起</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .linkbutton
        {
            margin-left: 20px;
            width: 85px;
        }
        table tr td
        {
            padding: 0px 5px;
        }
    </style>
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="searchForm" method="post">
            <table>
                <tr class="divLabel">
                    <td>
                        发动机号:
                    </td>
                    <td>
                        生产订单号:
                    </td>
                    <td>
                        订单类型:
                    </td>
                </tr>
                <tr>
                    <td>
                        <input class="easyui-textbox" type="text" name="Machine" style="width: 120px; height: 22px" />
                    </td>
                    <td>
                        <input class="easyui-textbox" type="text" name="mfgOrderName" style="width: 120px;
                            height: 22px" />
                    </td>
                    <td>
                        <input id="ORDERTYPE" name="OrderTypeIndex" style="width: 120px; height: 22px" />
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchData()">
                            查询</a>
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchReset()">
                            重置</a>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="订单列表" style="padding: 3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <table id="LaunchTable" style="height: 230px;width:100%">
            </table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
            </div>
        </div>
    </div>
    <div class="panelSection" id="EditorpanelSection">
        <div class="easyui-panel " title="编辑区域" style="padding: 3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="EditorForm">
            <table class="tabel" cellpadding="5">
                <tr class="divLabel">
                    <td>
                        生产订单号
                    </td>
                    <td>
                        退库类型
                    </td>
                    <td>
                        零件
                    </td>
                    <td>
                        批次号
                    </td>
                    <td>
                        退库数量
                    </td>
                    <td>
                        退库原因
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="mfgOrderID" type="hidden" /><input class="easyui-textbox" type="text"
                            name="mfgOrderName" style="width: 150px; height: 22px" id="mfgOrderName" />
                    </td>
                    <td>
                        <input class="easyui-textbox" type="text" name="ReturnType" style="width: 150px;
                            height: 22px" id="ReturnType" />
                    </td>
                    <td>
                        <input id="ProductID" type="hidden" /><input id="DESCRIPTION" type="hidden" /><input
                            id="PRODUCTNAME" type="hidden" /><div class="ProductCombox">
                            </div>
                    </td>
                    <td>
                        <input class="easyui-textbox" type="text" name="ReturnType" style="width: 150px;
                            height: 22px" id="ProductBatchNo" />
                    </td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="ReturnType" style="width: 150px;
                            height: 22px" id="StockReturnNum" />
                    </td>
                    <td>
                        <input class="easyui-textbox" type="text" name="ReturnType" style="width: 250px;
                            height: 22px" id="StockReturnReason" />
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.AppendRow()">
                            新增行 +</a> <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.DeleteRow()">
                                删除行 —</a>
                    </td>
                </tr>
            </table>
            </form>
            <div>
                <div style="width: 880px; float: left">
                    <table id="ReturnDetailTable" style="height: 200px;width:100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="退库申请" style="padding: 3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <table id="StockReturnApplyTable" style="height: 200px;">
            </table>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="padding: 3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 15px 0px">
                <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.saveStockReturnBillData()">
                    保存</a> <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.submitStockReturnBillData()">
                        提交</a> <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.deleteStockReturnBillData()">
                            删除</a>
            </div>
        </div>
    </div>
    <div id="statusMessage" style="font-size: 14px; height: 40px">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="">
/*
创建人：longb
日期：2023-01-06
描述：退库申请单-发起js
*/
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    editIndex:undefined,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSStockReturnApplyBillHandler.ashx",
    comboxUrl:getRootPath() + "/Ashx/ZsHandler/ZSSendRequestHandler.ashx",//combox下拉-调用后台的URL
    comboxAction:"GetAllProduct",//combox下拉-调用后台的具体方法
    //初始化页面
    init: function () {
        page.bind();
        customizedEasyuiPagination('pp'); //定制化分页
    },
    endEditing: function (gridId) {
        if (page.editIndex == undefined) { return true }
        if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
            $('#' + gridId).datagrid('endEdit', page.editIndex);
            page.editIndex = undefined;
            return true;
        } else {
            return false;
        }
    },
    //页面事件绑定
    bind: function () {
        $('#ORDERTYPE').combobox({
            data:[{id:0,text:'常规生产订单'},{id:1,text:'无物料号生产订单'}],
            valueField:'id',
            textField:'text',
            value:0
        });
        $('#ReturnType').combobox({
            data:[{id:0,text:'SCTL|生产退料'},{id:1,text:'其他'}],
            valueField:'id',
            textField:'text',
            value:0
        });
        
        
        //订单列表
        $("#LaunchTable").datagrid({
            rownumbers: true,
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            },
           
            columns: [[
                 //{ field: 'MFGORDERID', width: 120, checkbox: true },
                 { field: 'MACHINENO', title: '发动机号', width: 120},
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 150 },
                 { field: 'ORDERTYPENAME', title: '订单类型', width: 120 },
		         { field: 'MFGYPE', title: '订单类别', width: 130 }, //--
                 { field: 'PRODUCTNAME', title: '件号', width: 100 },
                 { field: 'PRODUCTDESCRIPTION', title: '件号名称', width: 120, },
                 { field: 'PRODUCTFAMILYNAME', title: '机型', width: 80 },
                 { field: 'FACTORYSTARDATE', title: '计划开始时间', width: 100 },
                 { field: 'FACTORYCOMPLETIONDATE', title: '计划结束时间', width: 100, }
	           ]],
            onSelect: function (index, row) {
               $('#mfgOrderName').textbox('setValue',row.MFGORDERNAME);
                $('#mfgOrderID').val(row.MFGORDERID);
                page.getStockReturnApplyData();
            }
        });
       $('#ReturnDetailTable').datagrid({
            singleSelect: true,
            columns: [[
                 { field: 'PRODUCTID',hidden:true },
                 { field: 'PRODUCTNAME', title: '零件编码', width: 170},
                 { field: 'DESCRIPTION', title: '零件名称', width: 150 },
                 { field: 'ProductBatchNo', title: '批次号', width: 120,editor:{type:'textbox'} },
		         { field: 'StockReturnNum', title: '退库数量', width: 130,editor:{type:'numberbox'} }, 
                 { field: 'StockReturnReason', title: '退库原因', width: 300,editor:{type:'textbox'} }
	           ]],
            onClickRow:function(index){
                if (page.editIndex != index){
				    if (page.endEditing('ReturnDetailTable')){
					    $('#ReturnDetailTable').datagrid('selectRow', index)
							    .datagrid('beginEdit', index);
					    page.editIndex = index;
				    } else {
					    $('#ReturnDetailTable').datagrid('selectRow', page.editIndex);
				    }
			    }
            },
            onAfterEdit:function(){
                 $('#ReturnDetailTable').datagrid('acceptChanges');
            }
        });
        $('.ProductCombox').selectCombox({
            search: function () { },
            cancel: function () {  $('#ProductID').val('');$('#DESCRIPTION').val('');$('#PRODUCTNAME').val('');},
            selected: function (val, text,record){
                $('#ProductID').val(val);
                $('#DESCRIPTION').val(record.DESCRIPTION);
                $('#PRODUCTNAME').val(record.PRODUCTNAME);
                $('#txtCombox').textbox('setValue',text);
                $('#divComboxTxt').show();
                $('#divComboxSelect').hide();
                $('#divComboxSearch').show();
                $('#divComboxClear').hide();
            }
        });

        $('#StockReturnApplyTable').datagrid({
             rownumbers: true,
             nowrap: false,
            columns: [[
                 { field: 'ZSSTOCKRETURNAPPLYBILLID', width: 120, checkbox: true },
                 { field: 'STOCKRETURNAPPLYBILLNO', title: '退库申请单号', width: 120},
                 { field: 'STOCKRETURNTYPE', title: '退库类型', width: 120,formatter:function(value,row,index){if(value=="0"){return'SCTL|生产退料';}else{return'其他';}}},
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 120},
                 { field: 'MACHINENO', title: '发动机号', width: 120},
                 { field: 'PRODUCTNAME', title: '零件编码', width: 120},
                 { field: 'PRODUCTDESCRIPTION', title: '零件名称', width: 150 },
                 { field: 'PRODUCTBATCHNO', title: '批次号', width: 120 },
		         { field: 'STOCKRETURNNUM', title: '退库数量', width: 130 }, //--
                 { field: 'STOCKRETURNREASON', title: '退库原因', width: 200 },
                 { field: 'STATUS', title: '状态', width: 100,formatter:function(value,row,index){if(value==2){return"已完成";}else if(value==1){return"待确认";}else{return"待提交";}} },
                 { field: 'CREATEDATENAME', title: '创建人', width: 100 },
                 { field: 'CREATEDATE', title: '创建时间', width: 150 },
                 { field: 'SUBMITNAME', title: '提交人', width: 100 },
                 { field: 'SUBMITDATE', title: '提交时间', width: 150 },
                 { field: 'CONFIRMNAME', title: '确认人', width: 100 },
                 { field: 'CONFIRMDATE', title: '确认时间', width: 150 }
	           ]],
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetOrderList();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.GetOrderList();
        });
        //清除按钮
        $('#btnReset').on("click", function () {
            page.reset(true, true);
            page.pageNumber = 1; page.pagetotal = 0
            $('#pp').pagination('refresh', {
                total: page.pagetotal,
                pageSize: page.pageSize,
                pageNumber: page.pageNumber
            });
        });
    },
   
    //查询
    searchData: function () {
        page.reset(false, true);
        page.pageNumber = 1;
        page.GetOrderList();
    },
    //查询订单列表信息
    GetOrderList: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = { };
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetOrderList",
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            data: JSON.stringify(data)
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                page.pagetotal = res.RowCount;
                $('#LaunchTable').datagrid('loadData', res.DBTable);
            }
        });
    },
    AppendRow:function(){
        if (page.endEditing('ReturnDetailTable')){
                page.reset();
                var insertRow={ProductID:$('#ProductID').val(),PRODUCTNAME:$('#PRODUCTNAME').val(),DESCRIPTION:$('#DESCRIPTION').val(),ProductBatchNo:$('#ProductBatchNo').textbox('getValue'),StockReturnNum:$('#StockReturnNum').numberbox('getValue'),StockReturnReason:$('#StockReturnReason').textbox('getValue')};
                if(insertRow.ProductID==""){displayMessage("请选择零件，再进行操作",false);return;}
                if(insertRow.ProductBatchNo==""){displayMessage("请输入批次号，再进行操作",false);return;}
                if(insertRow.StockReturnNum==""){displayMessage("请输入退库数量，再进行操作",false);return;}
                if(insertRow.StockReturnReason==""){displayMessage("请输入退库原因，再进行操作",false);return;}
                
                var index=undefined;
                var rows=$('#ReturnDetailTable').datagrid('getRows');
                $.each(rows,function(i,item){
                    if(item.ProductID==insertRow.ProductID){
                        index=i;
                        $('#ReturnDetailTable').datagrid('updateRow',{index:index,row:insertRow});
                        $('#ReturnDetailTable').datagrid('selectRow', index).datagrid('beginEdit', index);
                    }
                });
                if(index==undefined){
				    $('#ReturnDetailTable').datagrid('appendRow',insertRow);
				    page.editIndex = $('#ReturnDetailTable').datagrid('getRows').length-1;
				    $('#ReturnDetailTable').datagrid('selectRow', page.editIndex).datagrid('beginEdit', page.editIndex);
                }
	        }
    },
    DeleteRow:function(){
        if (page.editIndex == undefined){return}
			$('#ReturnDetailTable').datagrid('cancelEdit', page.editIndex).datagrid('deleteRow', page.editIndex);
			page.editIndex = undefined;
    },
    //保存退出单信息
    saveStockReturnBillData: function () {
        $('#ReturnDetailTable').datagrid('acceptChanges');
        var rows=$('#ReturnDetailTable').datagrid('getRows');
        var param = {
            action: "saveStockReturnBillData",
            ReturnType:$('#ReturnType').combobox('getValue'),
            mfgOrderID:$('#mfgOrderID').val(),
            data: JSON.stringify(rows)
        };
        page.post(param, function (res) {
            if (res.Result) {
                page.getStockReturnApplyData();
                $('#ReturnDetailTable').datagrid('loadData',[]);
            }
            displayMessage(res.Message, res.Result);
        });
    },
    ///获取退库申请单数据
    getStockReturnApplyData:function(){
       page.post({action:'getStockReturnApplyData',mfgOrderID:$('#mfgOrderID').val()}, function (res) {
          $('#StockReturnApplyTable').datagrid('loadData',res)
        });
    },
    ///提交退库申请单数据
    submitStockReturnBillData:function(){
        var rows=$('#StockReturnApplyTable').datagrid('getChecked');
        var data=[];
        $.each(rows,function(index,item){
            if(item.STATUS==0){
                data.push(item);
            }
        });
        if(data.length==0){displayMessage("请选择至少一条【待提交】退库申请单信息，再进行操作",false);return;}
         page.post({action:'updateStockReturnBillData',data:JSON.stringify(data),type:'submit'}, function (res) {
            if (res.Result) {
                page.getStockReturnApplyData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    ///删除退库申请单数据
    deleteStockReturnBillData:function(){
          var rows=$('#StockReturnApplyTable').datagrid('getChecked');
          var data=[];
            $.each(rows,function(index,item){
                if(item.STATUS==0){
                    data.push(item);
                }
            });
          if(data.length==0){displayMessage("请选择至少一条退库申请单信息，再进行操作",false);return;}
         page.post({action:'deleteStockReturnBillData',data:JSON.stringify(data)}, function (res) {
            if (res.Result) {
                page.getStockReturnApplyData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        page.bind();
    },

    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function ( param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});
</script>
<script src="/InSiteWebApplication/Scripts/ZsJs/selectCombox.js" type="text/javascript"></script>
